﻿// -----------------------------------------------------------------------
// <copyright file="RevisionRevisionAttachment_DAL.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace PMSGSC.DAL
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class RevisionAttachment_DAL:BaseDAL
    {
        
        // Lấy tất cả RevisionAttachment
        public static List<RevisionAttachment> GetAll(int shipID)
        {
            DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, DB.RevisionAttachments);
            return DB.RevisionAttachments.ToList();
        }
        // Lấy RevisionAttachment theo Id
        public static RevisionAttachment GetDataById(int id)
        {
            return DB.RevisionAttachments.Where(m => m.Attachment_ID == id).FirstOrDefault();
        }
        //Thêm một RevisionAttachment
        public static bool Insert(RevisionAttachment RevisionAttachment)
        {
            try
            {
                DB.RevisionAttachments.InsertOnSubmit(RevisionAttachment);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        // Xóa một RevisionAttachment
        public static bool Delete(RevisionAttachment RevisionAttachment)
        {
            try
            {
                DB.RevisionAttachments.DeleteOnSubmit(RevisionAttachment);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        // Cập nhật RevisionAttachment
        public static bool Update(RevisionAttachment RevisionAttachment)
        {
            try
            {
                //RevisionAttachment objRevisionAttachment = GetDataById(RevisionAttachment.RevisionAttachments);
                ////objRevisionAttachment.Code = RevisionAttachment.Code;
                ////objRevisionAttachment.Equipment_ID = RevisionAttachment.Equipment_ID;
                ////objRevisionAttachment.ContentFile = RevisionAttachment.ContentFile;
                ////objRevisionAttachment.Name = RevisionAttachment.Name;
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }

        // Kiểm tra xem RevisionAttachment Code có tồn tại chưa s
        public static bool IsExits(RevisionAttachment RevisionAttachment)
        {
            RevisionAttachment objRevisionAttachment = null;
            objRevisionAttachment = DB.RevisionAttachments.Where(m => (m.Code == RevisionAttachment.Code) &&
                (m.Attachment_ID != RevisionAttachment.Attachment_ID) && (m.Revision_ID == RevisionAttachment.Revision_ID)).FirstOrDefault();
            return objRevisionAttachment != null ? true : false;
        }
        public static List<RevisionAttachment> GetDataByRevisionID(int id, bool isChanged)
        {
            if (isChanged)
            {
                DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, DB.RevisionAttachments);
            }
            return DB.RevisionAttachments.Where(j => j.Revision_ID == id).ToList();
        }
      
    }
}
